﻿using M_Process.API.Appliction.Command.ReportingCommand;
using M_Process.Domain;
using M_Process.Repository.ProcessImpl;
using M_Process.Repository.ProcessInterface;
using MediatR;
using Microsoft.AspNetCore.JsonPatch.Operations;
using static System.Collections.Specialized.BitVector32;

namespace M_Process.API.Appliction.CommandHandlers.ReportingCommandHandler
{
    /// <summary>
    /// 添加报工命令处理器
    /// </summary>
    public class AddReportingCommandHandler : IRequestHandler<AddReportingCommand, int>
    {
        /// <summary>
        /// 报工仓储
        /// </summary>
        protected readonly IReportingRepository reportingRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="reportingRepository">报工仓储</param>
        public AddReportingCommandHandler(IReportingRepository reportingRepository)
        {
            this.reportingRepository = reportingRepository;
        }

        /// <summary>
        /// 处理添加报工命令
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(AddReportingCommand request, CancellationToken cancellationToken)
        {
            return await reportingRepository.AddAsync(new Reporting()
            {
                ReportingNum=request.ReportingNum,
                EquipmentName=request.EquipmentName,
                EquipmentNumber= $"BG{DateTime.Now.ToString("yyyyMMddHHmmssfff")}",
                Station=request.Station,
                TeamsAndGroups=request.TeamsAndGroups,
                ProcessTasksId=request.ProcessTasksId,
                Notes="",
                Operator ="张三",
                CreatedBy = "张三",
                CreatedDate = DateTime.Now
            });
        }
    }
}
